package com.woniuxy.controller;

import com.woniuxy.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import javax.validation.Valid;

@Controller
@RequestMapping("/User")
public class userValid {
    @RequestMapping("/adduser")
    public ModelAndView addUser(@Valid @RequestBody User user, BindingResult bindingResult){
        ModelAndView modelAndView= new ModelAndView();
        if(bindingResult.hasErrors()){
            FieldError fieldError = bindingResult.getFieldError();
            modelAndView.addObject("binding", fieldError.getField() + "" + bindingResult.getFieldError().getDefaultMessage());
        }
//        modelAndView.addObject("binding",user);
            modelAndView.setViewName("/WEB-INF/jsp/index.jsp");
        return modelAndView;
    }
    @RequestMapping("/aaa")
    public String aaa(){
        System.out.println("aaa");
        return "/index.jsp";
    }
}
